$(document).ready(function() {
	countNewMessage();
	setInterval(function(){
		countNewMessage();
	}, 3000);
	$("#toggleMenu").click(function(){ $("#menuToToggle").toggle(200); });
	
	var resizedWindow = $(window).resize(function(e) {
		var windowWidth = $(window).width();
		if(windowWidth <= 768)
		{
			$("#menuToToggle").css({
				'display':'none'	
			});
		}
		else
		{
			$("#menuToToggle").css({
				'display':'block'	
			});
		}
    });
	
	var getRefreshWidth = $(window).width();
	if(getRefreshWidth <= 768)
	{
		$("#menuToToggle").css({
			'display':'none'	
		});
	}
	else
	{
		$("#menuToToggle").css({
			'display':'block'
		});
	}


	$(".menuToggleBtnFront").click(function(){ $("#menuToToggleFront").toggle(200); });
	
	var resizedWindow = $(window).resize(function(e) {
		var windowWidth = $(window).width();
		if(windowWidth >= 768)
		{
			$("#menuToToggleFront").css({
				'display':'none'	
			});
		}
    });
	
	$('.doDelete').click(function(event){
		event.preventDefault();
		$(".overlayHolder").fadeToggle("fast");
		var getIDContent = $(this).attr('data-id');
		var getDataContent = $(this).attr('data-title');
		console.log(getDataContent);
		overlayConfirm = '';
		overlayConfirm += '<div class="confirmationHolder">';
			overlayConfirm += '<div class="headerConfirm"><i class="icon-trash"></i> Delete</div>';
			overlayConfirm += '<div class="confirmationContent">';
				overlayConfirm += 'Do you want to delete <strong>'+getDataContent+'</strong>?';
			overlayConfirm += '</div>';
			overlayConfirm += '<div class="confirmBtnHolder">';
				overlayConfirm += '<div class="btn-group">';
					overlayConfirm += '<button class="btn btn-mini btn-info doDeleteThis" data-id="'+getIDContent+'"><i class="icon-ok-sign"></i> Confirm</button>';
					overlayConfirm += '<button class="btn btn-mini btn-danger doCancel"><i class="icon-remove-sign"></i> Cancel</button>';
				overlayConfirm += '</div>';
			overlayConfirm += '</div>';
		overlayConfirm += '</div>';
		$('.boxOverlayContent').html(overlayConfirm);
		$('.doCancel').click(function(){
			$(".overlayHolder").hide();
		});
		$('.doDeleteThis').click(function(){
			var getItemID = $('.doDeleteThis').attr('data-id');
			setTimeout(function(){
				doDeleteResto(getItemID);
			},3000);
		});
	});
	$('.closeOverlay').click(function(){
		$(this).css({
			'display':'none'
		});	
	});
});
function doDeleteResto(intRestoID){
	uri = 'dashboard/delete_resto';
	data = {
		'intRestoID':intRestoID	
	};
	$.ajax({
		type: "POST",
		url: base_url+uri,
		data: data,
		dataType: 'json',
		success: function(result){
			var getItemID = $('.doDeleteThis').attr('data-id');
			
			$('#item_'+getItemID).remove('#item_'+getItemID);
			$(".overlayHolder").hide();
		}
	});
}
function countNewMessage(){
	uri = 'dashboard/count_new_msg';
	data = {};
	$.ajax({
		type: "POST",
		url: base_url+uri,
		data: data,
		dataType: 'json',
		success: function(result){
			if(result>0)
			{
				$('.newMsgCount').html('<span class="countMsgHolder">'+result+'</span>');
			}
			else
			{
				$('.newMsgCount').html('');
			}
		}
	});
}